package guoanmaker.provider.business.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import guoanmaker.provider.business.model.ProvideCity;
import guoanmaker.provider.business.model.ProvideCommodity;
import guoanmaker.provider.business.model.ProvideCommodityServiceRange;

public interface ProvideCommodityRepository extends JpaRepository<ProvideCommodity, String>,JpaSpecificationExecutor<ProvideCommodity>{
	    @Query("select comm from ProvideCommodity comm where comm.commodityState=:commodityState")
	    public List<ProvideCommodity> findByCommodityState(@Param("commodityState") Integer commodityState);
	    
	  /*  @Query("select comm from ProvideCommodity comm where comm.commodityName=:commodityName and comm.isBargaining=:isBargaining")
	    public List<ProvideCommodity> findByCommodityNameAndIsBargaining(@Param("commodityName") String commodityName,@Param("isBargaining") String isBargaining);*/
	    public List<ProvideCommodity> findByCommodityNameOrIsBargaining( String commodityName, String isBargaining);
	    
	    public Page<ProvideCommodity> findByCommodityNameIs( String commodityName,Pageable pageable);
	    
	@Query("select count(*) from ProvideCommodity p left join  p.providerBusiness pb where p.providerBusiness.id=:id")
	public Integer selectCommidityNum(@Param("id") String id);

	   // public Page<ProvideCommodity> findBybusiness_idIsAndCommodityNameIs(String business_id,String commodityName,Pageable pageable);
	   // public Page<ProvideCommodity> findBybusiness_idIsAndCommodityNameIs(String business_id,String commodityName,Pageable pageable);

	@Query("select com from ProvideCommodity com  left join  com.providerBusiness pb where pb.id=:id and com.commodityState=2")
	public List<ProvideCommodity>  selectByCommodity(@Param("id") String id);

	@Query("select s from ProvideCommodityServiceRange s left join  s.commodity c where  c.id=s.commodity.id  and  c.id=:id")
	public  List<ProvideCommodityServiceRange>    selectByServerArea(@Param("id") String id);
	
	@Query("select s from ProvideCommodity s  where  s.id=:id  and  s.commodityState =:status")
	public List<ProvideCommodity> selectByStatusId(@Param("id") String id,@Param("status") Integer status);
}
